package com.ttdj.cmel.utils;

import android.content.Context;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.ttdj.cmel.CMELApplication;

import java.lang.reflect.Method;

public class Utils {

    public static final int INSTALL_REPLACE_EXISTING = 0x00000002;

    /**
     * 获取手机Imei
     */
    public static String getPhoneImei() {
        TelephonyManager telManager = (TelephonyManager) CMELApplication.getApplication().
                getSystemService(Context.TELEPHONY_SERVICE);
        if (telManager != null) {
            String imei = telManager.getDeviceId();
            return imei;
        }
        return "";
    }

    public static String getAppVersion() {
        String versionName = "";
        int versioncode = 0;
        try {
            // ---get the package info---
            PackageManager pm = CMELApplication.getApplication().getPackageManager();
            PackageInfo pi = pm.getPackageInfo(CMELApplication.getApplication().getPackageName(), 0);
            versionName = pi.versionName;
            versioncode = pi.versionCode;
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e(CMELApplication.TAG, "getAppVersion_Exception", e);
        }
        return versionName;
    }
}